package ws.jdbc.concurrent.driver.sqlserver.tds.datatypes;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 *
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public class LONGLEN extends TYPE_VARLEN {

  //private static final int longSize = 4;

  public LONGLEN(int length) {
    super(length, 4);
  }

  @Override
  public byte[] getBytes() {
    return ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN).putInt((int) length).array();
  }

  @Override
  public int size() {
    return size;
  }

  @Override
  public TYPE_VARLEN read(final ByteBuffer is) throws IOException {
    length = is.getInt();
    return this;
  }

  @Override
  public boolean wasNull() {
    return length == GeneralRules.CHARBIN_NULL_4;
  }
}
